<template>
  <el-dialog v-model="visible" :title="!dataForm.id ? '新增' : '审核'" :close-on-click-modal="false"
    :close-on-press-escape="false">
    <el-form :model="dataForm" :rules="rules" ref="dataFormRef" @keyup.enter="dataFormSubmitHandle()"
      label-width="120px">
      <el-row :gutter="20">
        <el-col :span="24">
          <el-form-item label="公司" prop="companyId">
            <el-select disabled v-model="dataForm.companyId" placeholder="公司" class="w100">
              <el-option v-for="item in kxczxdf" :key="item.id" :label="item.name" :value="item.id" />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="姓名" >
           {{ dataForm.realName }}
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="联系方式">
           {{ dataForm.userMobile }}
          </el-form-item>
        </el-col>

        <el-col :span="12" v-if="dataForm.inviteRealName">
          <el-form-item label="邀请人姓名">
           {{ dataForm.inviteRealName }}
          </el-form-item>
        </el-col>
        <el-col :span="12" v-if="dataForm.inviteRealName">
          <el-form-item label="邀请人电话">
           {{ dataForm.inviteMobile }}
          </el-form-item>
        </el-col>
      </el-row>




      <el-form-item label="工作标题" >
        {{ dataForm.jobName }}
      </el-form-item>

   <el-form-item label="审核" prop="status">
        <el-radio-group v-model="dataForm.status">
          <el-radio :label="2">通过</el-radio>
          <el-radio :label="3">不通过</el-radio>
        </el-radio-group>
        <div class="mt10 w100" v-if="dataForm.status==3">
          <el-input v-model="dataForm.statusContent" type="textarea" rows="10" placeholder="请输入不通过的原因"></el-input>
        </div>

      </el-form-item>
      <el-form-item label="员工工号" v-if="dataForm.status==2">
        <div class=" display-flex w100">
            <div class=" flex-1">
              <el-input v-model="dataForm.companyNo"  placeholder="请绑定该员工工号"></el-input>
            </div>
        </div>
      </el-form-item>
      <!-- <el-form-item label="更新人" prop="updateOwner">
        <el-input v-model="dataForm.updateOwner" placeholder="更新人"></el-input>
      </el-form-item>
      <el-form-item label="更新时间" prop="updateTime">
        <el-input v-model="dataForm.updateTime" placeholder="更新时间"></el-input>
      </el-form-item>
      <el-form-item label="创建时间" prop="createTime">
        <el-input v-model="dataForm.createTime" placeholder="创建时间"></el-input>
      </el-form-item> -->
    </el-form>
    <template #footer>
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmitHandle()">确定</el-button>
    </template>
  </el-dialog>
</template>

<script lang="ts" setup>
import { reactive, ref } from "vue";
import baseService from "@/service/baseService";
import { ElMessage } from "element-plus";
import { dxget, zkjsd, transferTimeYMD,dxpost } from "@/utils/utils"
const emit = defineEmits(["refreshDataList"]);
const jxcfftry = ref()
const visible = ref(false);
const kxczxdf = ref([])
const dataFormRef = ref();
const radio = ref(3)
const kxzcdf = ref()
const dataForm = reactive({
  id: '', userId: '', realName: '', userMobile: '', jobId: '', jobName: '', companyId: '', status: '', updateOwner: '', updateTime: '', createTime: ''
});

const rules = ref({
  userId: [
    { required: true, message: '必填项不能为空', trigger: 'blur' }
  ],
  realName: [
    { required: true, message: '必填项不能为空', trigger: 'blur' }
  ],
  userMobile: [
    { required: true, message: '必填项不能为空', trigger: 'blur' }
  ],
  jobId: [
    { required: true, message: '必填项不能为空', trigger: 'blur' }
  ],
  jobName: [
    { required: true, message: '必填项不能为空', trigger: 'blur' }
  ],
  companyId: [
    { required: true, message: '必填项不能为空', trigger: 'blur' }
  ],
  status: [
    { required: true, message: '必填项不能为空', trigger: 'blur' }
  ],
  updateOwner: [
    { required: true, message: '必填项不能为空', trigger: 'blur' }
  ],
  updateTime: [
    { required: true, message: '必填项不能为空', trigger: 'blur' }
  ],
  createTime: [
    { required: true, message: '必填项不能为空', trigger: 'blur' }
  ]
});

const init = (id?: number) => {
  visible.value = true;
  dataForm.id = "";

  // 重置表单数据
  if (dataFormRef.value) {
    dataFormRef.value.resetFields();
  }

  if (id) {
    getInfo(id);
  }
};

// 获取信息
const getInfo = (id: number) => {
  baseService.get("/api/jobregist/" + id).then((res) => {
    Object.assign(dataForm, res.data);
    dataForm.status = parseInt(dataForm.status)
  });
};
// const xzczxstertery = async()=>{
//   await dxpost("/api/user",{
//     id:dataForm.userId,
//     companyNo:jxcfftry.value,
//     companyId:dataForm.companyId,
//     isJob:true,
//     companyTime:transferTimeYMD(new Date())
//   },"put")
// }
// 表单提交
const dataFormSubmitHandle = () => {
  dataFormRef.value.validate((valid: boolean) => {
    dataForm.isJob = true
    dataForm.companyTime = transferTimeYMD(new Date())
    if (!valid) {
      return false;
    }
   (!dataForm.id ? baseService.post : baseService.put)("/api/jobregist", dataForm).then(async(res) => {
      ElMessage.success({
        message: '成功',
        duration: 500,
        onClose: () => {
          // xzczxstertery()
          visible.value = false;
          emit("refreshDataList");
        }
      });
    });
  });
};

defineExpose({
  init
});


const injxsd = async () => {
  const resd = await dxget("/sys/tmcompany/option")
  kxczxdf.value = resd
}
injxsd()




</script>
